package com.example.nna.util;

import java.util.ArrayList;

import com.example.nna.voz.containPage2;

import android.content.Context;
import android.database.Cursor;


public class Subscribe {
	private DBAdapter1 db;
	private ArrayList<containPage2> containsFavourite;
	public Subscribe(Context context){
		db = new DBAdapter1(context);
		initSqlite();
	}
	public void initSqlite(){
		containsFavourite = new ArrayList<containPage2>();
    	db.open();
    	Cursor c = db.getAllContacts();
			if(c.moveToFirst()){
  			do{
  				containsFavourite.add(new containPage2(c.getString(1),null,
  						null, null, null, c.getString(2), null,true));
  			}while(c.moveToNext());
			}
		db.close();
	}
	public ArrayList<containPage2> listSubcribe(){
		initSqlite();
		return containsFavourite;
	}
	public void delete(String thread){
		db.open();
		db.deleteThread(thread);
		db.close();	
	}
	public void insert(String thread,String url){
		db.open();
		db.insertContact(thread, url);
		db.close();	
	}
	public String getThread(int pos){
		String url = null;
		db.open();
		Cursor c = db.getThread("thread='"+containsFavourite.get(pos).Thread()+"'",
				 null, null, null, null);
		if(c.moveToFirst()){
	  			do{
	  				url = c.getString(2);
	  			}while(c.moveToNext());
  		}
  		db.close();
  		return url;
	}
	public boolean isSubscribe(String url){
		boolean is = false;
		for(int i=0;i<containsFavourite.size();i++){
			if(containsFavourite.get(i).UrlThread().equals(url))
				is = true;
		}
		return is;
	}
	
}
